<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2016/6/8
  Time: 19:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" href="/wechat/login/modified.css">
    <jsp:include page="../public/head.jsp" flush="true" />
</head>
<body>
<jsp:include page="../public/header.jsp" flush="true" />
<section >
    <div class="my_modified">
        <form id="form" onsubmit="return false">
            <c:choose>
                <c:when test="${empty sessionScope.userinfo}">
                    <input type="hidden" value="${mobile}" name="mobile">
                </c:when>
                <c:otherwise>
                    <input type="hidden" value="${userinfo.mobile}" name="mobile">
                </c:otherwise>
            </c:choose>
            <div class="row1">
                <i class="iconfont icon-phone">&#xe600;</i>
                <span>新密码:</span>
                <input type="password"  value="" name="password" placeholder="请输入新密码" class="user-name"  data-caution="新密码不能为空" id="pwd">
            </div>
            <!--/row-->
            <div class="row1">
                <i class="iconfont icon-phone">&#xe600;</i>
                <span>确认密码:</span>
                <input type="password"  value="" placeholder="确认密码" class="user-name" data-caution="密码不能为空" id="newPwd">
            </div>
            <!--/row1-->
            <input type="button" value="确定" class="user-agree" onclick="modifyPwd()">
        </form>
    </div>
</section>
<script>
    function modifyPwd() {
        var checkpwd = /^[0-9a-zA-Z]*$/g;

        if ($("#pwd").val().length == 0){
            tip("","还未输入密码",true);
            return;
        }
        if ($("#newPwd").val().length == 0){
            tip("","还未输入确认密码",true);
            return;
        }

        if ($("#pwd").val().length < 6){
            tip("","密码过短",true);
            return;
        }
        if ($("#pwd").val().length > 16){
            tip("","密码过长",true);
            return;
        }
        if (!checkpwd.test($("#pwd").val())){
            tip("","密码只能为数字和字母",true);
            return;
        }

        var pwd = $("#pwd").val();
        var newPwd = $("#newPwd").val();

        if (pwd != newPwd){
            tip("","两次密码不一致",true);
            return;
        }

        $.post("/mobile/user?action=resetPass",$("#form").serialize(),
        function(data){

            if (!data.success){
                tip("",data.msg,true);
            }else {
                tip("",data.msg,true);
                window.location.href = "/login.do";
            }
        },"json");
    }
</script>
</body>
</html>
